<template>
  <!-- 来料检任务清单 -->
  <p-card :bordered="false">
    <!-- 进料检验类型开始 -->


      <p-form-model
        ref="baseInfoData"
        :model="baseInfoData"
        :rules="rules"
        :label-col="labelCol"
        :wrapper-col="wrapperCol"

      >
        <p-page-header
                style="border: 1px solid rgb(235, 237, 240)"
                title="来料检验操作"
        >
          <template slot="extra">

            <p-button key="1" type="primary" @click="saveDataBtn">
              保存
            </p-button>

            <p-popconfirm
                    title="确定要提交吗？"
                    ok-text="确定"
                    cancel-text="取消"
                    @confirm="submitData"
                    @cancel="cancel"
            >
              <p-button type="primary">提交</p-button>
            </p-popconfirm>
            <p-button @click="backToIndex">取消</p-button>
          </template>
        </p-page-header>
        <h4 class="title">基础信息</h4>
        <p-row :gutter="24">
          <p-col :span="8">
            <p-form-model-item ref="inspectBillno" label="送检单号" prop="inspectBillno" >
              <p-input
                      readOnly
                v-model="baseInfoData.inspectBillno"
                      v-decorator="['inspectBillno', { rules: [{ required: true, message: '请输入送检单号!' }] }]"
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="sendBillno" label="送货单号" prop="sendBillno">
              <p-input
                      readOnly
                v-model="baseInfoData.sendBillno"
                @blur="
          () => {
            $refs.sendBillno.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="sendBillnoLine" label="送货单行号" prop="sendBillnoLine">
              <p-input
                      readOnly
                v-model="baseInfoData.sendBillnoLine"
                @blur="
          () => {
            $refs.sendBillnoLine.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="mcode" label="物料编号" prop="mcode">
              <p-input
                      readOnly
                v-model="baseInfoData.mcode"
                @blur="
          () => {
            $refs.mcode.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="mname" label="物料名称" prop="mname">
              <p-input
                      readOnly
                v-model="baseInfoData.mname"
              >
                <p-tooltip slot="suffix" :title="baseInfoData.mname">
                  <p-icon type="info-circle" style="color: rgba(0,0,0,.45)" />
                  </p-tooltip>
              </p-input>
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="workBillno" label="工单号" prop="workBillno">
              <p-input
                      v-if="baseInfoData.workBillno&&baseInfoData.workBillno!=''"
                      readOnly
                      v-model="baseInfoData.workBillno"
              />
              <p-input v-else  default-value="/" readOnly />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="productOneType" label="物料一级分类" prop="productOneType">
              <p-input
                      readOnly
                      v-model="baseInfoData.productOneType"

              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="productTwoType" label="物料二级分类" prop="productTwoType">
              <p-input

                      readOnly
                v-model="baseInfoData.productTwoType"
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="productThreeType" label="物料三级分类" prop="productThreeType">
              <p-input
                      readOnly
                v-model="baseInfoData.productThreeType"
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="sampingMethod" label="抽检方式" prop="sampingMethod">
              <p-input
                      v-if="baseInfoData.sampingMethod==1"
                      readOnly
                v-model="baseInfoData.simpleMethodText"
              />

              <p-input
                      v-else
                      readOnly
                      v-model="baseInfoData.aqlSimpleStandardName"
              />

            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="simpleQty" label="抽检数量" prop="simpleQty">
              <p-input
                      :disabled="visible==2"
                      type="number"
                v-model="baseInfoData.simpleQty"

              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="matSn" label="物料管控方式" prop="matSn">
              <p-input
                      readOnly
                      style="color:red"
                v-model="baseInfoData.matSnText"
                @blur="
          () => {
            $refs.matSn.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="custno" label="供应商编码" prop="custno">
              <p-input
                      readOnly
                v-model="baseInfoData.custno"
                @blur="
          () => {
            $refs.custno.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="custname" label="供应商名称" prop="custname">
              <p-input
                      readOnly
                v-model="baseInfoData.custname"
                @blur="
          () => {
            $refs.custname.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="sendInspectTime" label="送检时间" prop="sendInspectTime">
              <p-input
                      readOnly
                v-model="baseInfoData.sendInspectTime"
                @blur="
          () => {
            $refs.sendInspectTime.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="sendInspectQty" label="送检数量" prop="sendInspectQty">
              <p-input
                      readOnly
                v-model="baseInfoData.sendInspectQty"
                @blur="
          () => {
            $refs.sendInspectQty.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>

          <p-col :span="8" v-if="visible==1">

            <p-form-model-item ref="sendInspectBy" label="送检人" prop="sendInspectBy">
              <p-input
                      readOnly
                      v-model="baseInfoData.sendInspectBy"
                      @blur="
          () => {
            $refs.sendInspectBy.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>

          <p-col :span="8">
            <p-form-model-item ref="inMethod" label="来料方式" prop="inMethod">
              <p-select
                      v-model="baseInfoData.inMethod"
                      @blur="() => {$refs.inMethod.onFieldBlur();}"
                      disabled
              >
                <p-select-option :value="1">
                  进料检验
                </p-select-option>
                <p-select-option :value="2">
                  直发协同
                </p-select-option>
              </p-select>



            </p-form-model-item>
          </p-col>

          <p-col :span="8" v-if="visible==1">

            <p-form-model-item ref="currentAddress" label="当前地址" prop="currentAddress">
              <p-input
                      readOnly
                      v-model="baseInfoData.currentAddress"
                      @blur="
          () => {
            $refs.currentAddress.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>


          <p-col :span="8" >

            <p-form-model-item ref="checkBy" label="检验人" prop="checkBy">
              <p-input
                      readOnly
                      v-model="baseInfoData.checkBy"
                      @blur="
          () => {
            $refs.checkBy.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>


          <p-col :span="8" v-if="visible==1">

            <p-form-model-item ref="questionRemark" label="问题备注" prop="questionRemark">
              <p-input
                      v-model="baseInfoData.questionRemark"
              />
            </p-form-model-item>
          </p-col>


        </p-row>
        <p-row>
          <p-col :span="5">
            <p-tag>供应商报告*</p-tag><a @click="queryCustReport">查询</a>
          </p-col>
          <p-col :span="5">
            <p-tag>物料SN详情*</p-tag><a @click="openPdSnDetailModal">查询</a>
          </p-col>
          <p-col :span="5">
            <p-tag>封样图片*</p-tag>
            <a v-if="baseInfoData.photoUrl&&baseInfoData.photoUrl!=''" @click="openViewBasicPhoto">查询</a>
            <span v-else>无图片</span>
          </p-col>
          <p-col :span="5">
            <p-tag>技术规格书*</p-tag><a>查询</a>
          </p-col>
          <p-col :span="4">
            <p-tag>检验结论*</p-tag>
            <p-span v-if="baseInfoData.inspectResult==1" style="color:blue">合格</p-span>
            <p-span v-else-if="baseInfoData.inspectResult==2" style="color:red">不合格</p-span>
          </p-col>


        </p-row>



      </p-form-model>
    <p-page-header
            style="border: 1px solid rgb(235, 237, 240)"
            title="检验项目"
    >
      <template slot="extra">

        <p-button key="1" type="primary" @click="addCheckProjectBtn" v-if="visible=='1'">
          新增行
        </p-button>


      </template>
    </p-page-header>
      <p-table
        :columns="baseInfoData.inMethod==1?modal1InspectionColumns:modal1InspectionColumns2"
        :data-source="baseInfoData.checkProjectList"
        class="components-table-demo-nested"
        bordered
        :expandIcon="expandIcon"
        style="margin-top:10px;"
      >
        <template slot="photoUrl" slot-scope="text,record">

          <p-button type="primary" icon="upload"  @click="openPhUpBtn2(record)" :disabled="baseInfoData.inMethod==2">上传</p-button>
          <p-divider type="vertical" v-if="record.photoUrl&&record.photoUrl!=''"/>
          <p-button v-if="record.photoUrl&&record.photoUrl!=''" type="primary" icon="eye" @click="openPhReviewBtn2(record)">预览</p-button>
        </template>

        <template slot="operation" slot-scope="text,record">
          <p-popconfirm
                  title="确定要删除此项？"
                  ok-text="删除"
                  cancel-text="取消"
                  @confirm="deleteCheckProject(record)"
          >
            <a href="#">删除</a>
          </p-popconfirm>
        </template>


        <p-table
          slot="expandedRowRender"
          slot-scope="text"
          :columns="modal1InspectionInnerColumns"
          :data-source="text.detailList"
          :pagination="false"

          bordered
        >



          <template slot="measuredValue" slot-scope="text,record">

            <p-select v-if="record.valueType==2" v-model="record.measuredValue" style="width: 100px;" :disabled="baseInfoData.inMethod==2" placeholder="please select your zone" @change="individualJudgmentChange">
              <p-select-option
                      v-for="(item,index) in passNgOptions"
                      :key="index"
                      :value="item.value"
              >{{item.name}}</p-select-option>
            </p-select>
            <p-input v-else type="number"  v-model="record.measuredValue " :disabled="baseInfoData.inMethod==2" style="width: 100px;" @change="individualJudgmentChange"  />
          </template>




          <template slot="defectLevel" slot-scope="text,record">
            <p-select v-model="record.defectLevel" placeholder="please select your zone" :disabled="true">
              <p-select-option
                v-for="(item,index) in defectLevelOptions"
                :key="index"
                :value="parseInt(item.value)"
              >{{item.title}}</p-select-option>
            </p-select>
          </template>
        </p-table>

      </p-table>

      <h4 class="title" v-if="visible==2">审批处理</h4>
      <p-form-model
              v-if="visible==2"
              ref="processProcessingData"
              :label-col="{span:2}"
              :wrapper-col="{span:12}"
              :model="baseInfoData"
              style="margin-top:12px;"
      >
        <p-row :gutter="24">
          <p-col :span="24">
            <p-form-model-item ref="operation" label="操作" prop="operation">
              <p-radio-group v-model="baseInfoData.operation">
                <p-radio :value="1">通过</p-radio>
                <p-radio :value="2">驳回</p-radio>
              </p-radio-group>
            </p-form-model-item>
          </p-col>
          <p-col :span="24">
            <p-form-model-item ref="inspectMethod" label="检验方式" prop="inspectMethod">
              <p-radio-group v-model="baseInfoData.inspectMethod">
                <p-radio :value="1">视讯检验</p-radio>
                <p-radio :value="2">驻厂检验</p-radio>
                <p-radio :value="3">检验报告审查</p-radio>
              </p-radio-group>
            </p-form-model-item>
          </p-col>
          <p-col :span="24">
            <p-form-model-item ref="remark" label="备注" prop="remark">
              <p-input
                      v-model="baseInfoData.remark"
                      type="textarea"

              />
            </p-form-model-item>
          </p-col>
          <p-col :span="24">
            <p-form-model-item ref="fileUrl" label="附件" prop="fileUrl">
              <p-button>上传</p-button>
            </p-form-model-item>
          </p-col>
        </p-row>
      </p-form-model>




    <!-- 进料检验类型结束 -->

    <div>
      <p-modal :visible="addCPModalVisible" width="60vw" title="新增行-检验项目" @ok="sureAddCheckProject" @cancel="closeAddCPModal" okText="添加" cancelText="取消">
        <p-alert message="请勾选包含检验明细的检验项目" type="info" v-if="selectedType==1" show-icon />
        <p-alert message="满足条件，点击“添加”按钮插入" type="success" v-if="selectedType==2" show-icon />
        <p-alert message="该项没有对应的明细列表" type="warning" v-if="selectedType==3" show-icon />

        <h4 class="title"></h4>
        <p-table
                :data-source="templateList"
                :columns="templateListColumns"
                :rowSelection="{ selectedRowKeys: selectedRowKeysArray, onChange: onSelectChange, type: 'radio' }"
        >

          <div
                  slot="filterDropdown"
                  slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
                  style="padding: 8px"
          >
            <p-input
                    v-ant-ref="c => (searchInput = c)"
                    :placeholder="`搜索 ${column.title}`"
                    :value="selectedKeys[0]"
                    style="width: 188px; margin-bottom: 8px; display: block;"
                    @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])"
                    @pressEnter="() => handleSearch(selectedKeys, confirm, column.dataIndex)"
            />
            <p-button
                    type="primary"
                    icon="search"
                    size="small"
                    style="width: 90px; margin-right: 8px"
                    @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)"
            >
              搜索
            </p-button>
            <p-button size="small" style="width: 90px" @click="() => handleReset(clearFilters)">
              重置
            </p-button>
          </div>
          <p-icon
                  slot="filterIcon"
                  slot-scope="filtered"
                  type="search"
                  :style="{ color: filtered ? '#108ee9' : undefined }"
          />
          <template slot="customRender" slot-scope="text, record, index, column">
      <span v-if="searchText && searchedColumn === column.dataIndex">
        <template
                v-for="(fragment, i) in text
            .toString()
            .split(new RegExp(`(?<=${searchText})|(?=${searchText})`, 'i'))"
        >
          <mark
                  v-if="fragment.toLowerCase() === searchText.toLowerCase()"
                  :key="i"
                  class="highlight"
          >{{ fragment }}</mark
          >
          <template v-else>{{ fragment }}</template>
        </template>
      </span>
            <template v-else>
              {{ text }}
            </template>
          </template>
        </p-table>

        <h4 class="title"></h4>
        <p-table
                :data-source="templateListDetails"
                :columns="templateListDetailsColumns"
        >

        </p-table>


      </p-modal>


      <p-modal v-model="pdSnDetailModalVisible" title="物料SN详情" :footer="null" :width="1200">
        <p-table
                :data-source="baseInfoData.matSnDetail"
                :columns="pdSnDetailColumns"
        >
        </p-table>
      </p-modal>





    </div>


    <p-modal v-model="phUpVisible2" title="图片上传" @ok="phUpSave2"  okText="保存更改">
      <j-upload v-model="currentDetailPhObj" :trigger-change="true" :ismultiSelect="false"></j-upload>
    </p-modal>



    <div>
      <p-modal v-model="dPhVisible" title="图片预览(非图片文件无法预览)" :footer="null" :width="1000">
        <img :src="dPhUrl" class="myImg"/>
      </p-modal>
    </div>

    <p-modal v-model="custReportModalVisible" title="供应商报告" :footer="null" :width="1300">

    </p-modal>


    <!-- 查询区域-END -->
  </p-card>
</template>

<script>
// import { JeecgListMixin } from "@/mixins/JeecgListMixin";
// import { api } from "@/api/manage";
// import JSuperQuery from "@/components/jeecg/JSuperQuery.vue";
// import { filterObj } from "@/utils/util";
// import MesQcIncomeBasicInfoModal from "./modules/MesQcIncomeBasicInfoModal";
// import Vue from "vue";
// import MesQcIncomeCheckProjectList from "./MesQcIncomeCheckProjectList";
// import MesQcIncomeFailList from "./MesQcIncomeFailList";
// import {
//   initDictOptions,
//   filterMultiDictText,
// } from "@/components/dict/JDictSelectUtil";
// import ButtonExpHandler from "@/components/jeecgbiz/modules/ButtonExpHandler";
// import { postAction, getAction, deleteAction } from "@/api/manage";
// import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal";

import {getAction, deleteAction, putAction, postAction} from "../../../api/manage";
import MesBcTemplateList from "./MesBcTemplateList";
import JUpload from '@/components/jeecg/JUpload'
export default {
  name: "MesIncomeOperation",
  components: {MesBcTemplateList,JUpload},
  // mixins: [JeecgListMixin],
  // components: {
  //   JSuperQuery,
  //   MesQcIncomeCheckProjectList,
  //   MesQcIncomeFailList,
  //   FxCompontensModal,
  //   MesQcIncomeBasicInfoModal,
  // },
  props:['mqVisible','mqLoad','mqData'],
  data() {
    return {
      labelCol: { span: 8 },
      wrapperCol: { span: 14 },

      baseInfoId:{},
      inMethod:{},

      visible: "1",
      //来料操作弹窗
      modal1Visible: false,
      //新增行弹出框
      addCPModalVisible:false,

      currentD:{},
      currentDetailPhObj:'',
      phUpVisible2:false,
      dPhUrl:'',
      dPhVisible:false,

      templateList:[],
      templateListDetails:[],
      selectedRowKeysArray:[],
      selectedRows:[],
      selectedType:1,
      inspectMethodList:[],
      inspectMethodMap:[],
      standardUnitList:[],
      standardUnitMap:[],

      basicResult:1,
      baseInfoData: {

      },
      custReportModalVisible:false,



      templateListColumns:[
        { title: "抽样样本",
          dataIndex: "sample",
          key: "sample",
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'customRender',
          },
          onFilter: (value, record) =>
                  record.sample
                          .toString()
                          .toLowerCase()
                          .includes(value.toLowerCase()),
          onFilterDropdownVisibleChange: visible => {
            if (visible) {
              setTimeout(() => {
                this.searchInput.focus();
              }, 0);
            }
          },
        },
        { title: "物料编码", dataIndex: "mcode", key: "mcode" },
        { title: "物料名称", dataIndex: "mname", key: "mname" },
      ],
      templateListDetailsColumns:[
        { title: "检验项目", dataIndex: "inspectItem", key: "inspectItem" },
        { title: "检验标准", dataIndex: "inspectStandard", key: "inspectStandard" },
        { title: "值类型", dataIndex: "valueType", key: "valueType",
          customRender: (text) => {
            if (!text) {
              return "";
            } else {
              return text==1?'计量型':'计数型';
            }
          },
        },
        { title: "标准值", dataIndex: "standardValue", key: "standardValue" },
        { title: "上限值", dataIndex: "upperValue", key: "upperValue" },
        { title: "下限值", dataIndex: "downValue", key: "downValue" },
      ],

      rules: {
        inspectBillno: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        sendBillno: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        sendBillnoLine: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],

        mcode: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        mname: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        mbig: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        msmall: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        sampingMethod: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        simpleQty: [
          {
            required: true,
            message: "请输入抽检数量！",
            trigger: "blur",
          },
        ],
        matSn: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        custno: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        custname: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        sendInspectTime: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        sendInspectQty: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        checkBy: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        sendInspectBy: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        inMethod: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],

        currentAddress: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        custReport: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        tcsp: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        mSnDetail: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        photoUrl: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
        inspectResult: [
          {
            required: true,
            message: "Please input Activity name",
            trigger: "blur",
          },
        ],
      },
      // 进料检验类型数据
      modal1InspectionColumns2: [
        {
          title: "序号",
          dataIndex: "key",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          },
        },
        { title: "抽样样本", dataIndex: "sample", key: "sample" },
        { title: "物料编码", dataIndex: "mcode", key: "mcode" },
        { title: "物料名称", dataIndex: "mname", key: "mname" },
        { title: "物料一级分类", dataIndex: "productOneType", key: "productOneType" },
        { title: "物料二级分类", dataIndex: "productTwoType", key: "productTwoType" },
        { title: "物料三级分类", dataIndex: "productThreeType", key: "productThreeType" },
        { title: "检验结果",
          dataIndex: "inspectResult",
          key: "inspectResult",
          customRender: (text) => {
            if (!text) {
              return "";
            } else {
              return text==1?'合格':'不合格';
            }
          },
        },
        {
          title: "图片",
          key: "photoUrl",
          dataIndex: 'photoUrl',
          scopedSlots: { customRender: "photoUrl" },
        },

      ],
      // 进料检验类型数据
      modal1InspectionColumns: [
        {
          title: "序号",
          dataIndex: "key",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          },
        },
        { title: "抽样样本", dataIndex: "sample", key: "sample" },
        { title: "物料编码", dataIndex: "mcode", key: "mcode" },
        { title: "物料名称", dataIndex: "mname", key: "mname" },
        { title: "物料一级分类", dataIndex: "productOneType", key: "productOneType" },
        { title: "物料二级分类", dataIndex: "productTwoType", key: "productTwoType" },
        { title: "物料三级分类", dataIndex: "productThreeType", key: "productThreeType" },
        { title: "检验结果",
          dataIndex: "inspectResult",
          key: "inspectResult",
          customRender: (text) => {
            if (!text) {
              return "";
            } else {
              return text==1?'合格':'不合格';
            }
          },
        },
        {
          title: "图片",
          key: "photoUrl",
          dataIndex: 'photoUrl',
          scopedSlots: { customRender: "photoUrl" },
        },
        {title:"操作",key:"id",dataIndex: 'id',scopedSlots: {customRender: "operation"}}
      ],

      modal1InspectionInnerColumns: [
        {
          title: "序号",
          dataIndex: "key",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          },

        },
        { title: "检验项目", dataIndex: "inspectItem", key: "inspectItem" },
        {
          title: "检验标准",
          dataIndex: "inspectStandard",
          key: "inspectStandard",
        },
        {
          title: "值类型",
          key: "valueType",
          dataIndex:'valueType',
          customRender: (text) => {
            if (!text) {
              return "";
            } else {
              return  text==1?"计量型":"计数型";
            }
          },
        },
        { title: "标准值", dataIndex: "standardValue", key: "standardValue",  },
        {title:"检验手段", dataIndex: "inspectMethod", key: "inspectMethod",
            customRender:(text)=> {
              if (!text) {
                return "";
              } else {
                return this.inspectMethodMap[text].title;
              }
            }
     },
        {
          title: "单位",
          align: "center",
          dataIndex: "standardUnit",
          customRender: (text) => {
            return this.standardUnitMap[text]?this.standardUnitMap[text].title:'';

          },
        },
        {
          title: "上限值",
          dataIndex: "upperValue",
          key: "upperValue",

        },
        { title: "下限值", dataIndex: "downValue", key: "downValue" },
        { title: "参数", dataIndex: "param", key: "param", },
        {
          title: "实测值",
          dataIndex: "measuredValue",
          key: "measuredValue",
          scopedSlots: { customRender: "measuredValue" },
        },
        {
          title: "单项判定",
          dataIndex: "individualJudgment",
          key: "individualJudgment",
          customRender: (text) => {
            if (!text) {
              return "";
            } else {
              return  text==1?"PASS":"NG";
            }
          },
        },
        {
          title: "缺陷等级",
          dataIndex: "defectLevel",
          key: "defectLevel",
          scopedSlots: { customRender: "defectLevel" },
        },
        { title: "供应商检验样本1", dataIndex: "custBook1", key: "custBook1" },
        { title: "供应商检验样本2", dataIndex: "custBook2", key: "custBook2" },
        { title: "供应商检验样本3", dataIndex: "custBook3", key: "custBook3" },
      ],


      valueTypeOptions:[
        {value:1,name:'计数型'},
        {value:2,name:'计量型'},
      ],

      passNgOptions:[
        {
          name: "PASS",
          value: "PASS",
        },
        {
          name: "NG",
          value: "NG",
        },
      ],
      measuredValueOptions: [
        {
          name: "pass",
          value: 1,
        },
        {
          name: "NG",
          value: 2,
        },
      ],
      simpleMethodList:[],
      simpleMethodMap:[],
      pdSnDetailModalVisible:false,
      viewBasicPhoto:false,
      defectLevelOptions: [
        { name: "空", value: 1 },
        { name: "A", value: 2 },
        { name: "B", value: 3 },
        { name: "C", value: 4 },
        { name: "D", value: 5 },
      ],


      // 直发协同类型数据
      modal2Visible: false,
      baseInfoData2: {
        //基础信息
        inspectBillno: "001", //送检单号
        sendBillno: "", //送货单号
        sendBillnoLine: "001", //送货单行号
        mcode: "", //物料编号
        mname: "", //物料名称
        mbig: "", //物料大类名称
        msmall: "", //物料小类名称
        sampingMethod: "", //抽检方式
        simpleQty: "3", //抽检数量
        matSn: "2020-01-01", //物料管理方式
        custno: "", //供应商编码
        custname: "", //供应商名称
        sendInspectTime: 1, //送检时间
        sendInspectQty: 3, //送检数量
        checkBy: "fdafsdd", //检验人
        inMethod: "", //来料方式
        custReport: "", //供应商报告
        tcsp: "", //技术规格书
        mSnDetail: "", //物料SN详情
        photoUrl: "", //封样图片
        inspectResult: "", //检验结论
        operation: 1, //操作
        inspectMethod: 1, //检验方式
        questionRemark: "", //备注
        fileUrl: "", //附件
      },
      pdSnDetailColumns:[
        { title: "物料编码", dataIndex: "mcode", key: "mcode" },
        { title: "物料名称", dataIndex: "mname", key: "mname" },
        { title: "物料一级分类", dataIndex: "productOneType", key: "productOneType" },
        { title: "物料二级分类", dataIndex: "productTwoType", key: "productTwoType" },
        { title: "物料三级分类", dataIndex: "productThreeType", key: "productThreeType" },
        { title: "SN", dataIndex: "sn", key: "sn" },
      ],
      modal2InspectionColumns: [
        {
          title: "序号",
          dataIndex: "key",
        },
        { title: "抽样样本", dataIndex: "sample", key: "sample" },
        { title: "物料编码", dataIndex: "mcode", key: "mcode" },
        { title: "物料名称", dataIndex: "mname", key: "mname" },
        { title: "物料小类", dataIndex: "subcategory", key: "subcategory" },
        { title: "物料大类", dataIndex: "mcategory", key: "mcategory" },
        { title: "检验结果", dataIndex: "inspectResult", key: "inspectResult",
          customRender: (text) => {
            if (!text) {
              return "";
            } else {
              return text==1?'合格':'不合格';
            }
          },
        },
        {
          title: "图片",
          key: "photoUrl",
          scopedSlots: { customRender: "photoUrl" },
        },
      ],


    };
  },
  computed: {

  },



  created() {
    this.initSimpleMethodList();
    this.initDefectLevelOptions();
    this.mqListener();
    this.initInspectMethodList();
    this.initStandardUnitList();
    // this.initButtonList();
    // this.initColumns();
    // this.setdefColumns();
    //this.initData();
  },

  methods: {
    handleSearch(selectedKeys, confirm, dataIndex) {
      confirm();
      this.searchText = selectedKeys[0];
      this.searchedColumn = dataIndex;
      this.resetRadioSelect();
    },
    handleReset(clearFilters) {
      clearFilters();
      this.searchText = '';
      this.resetRadioSelect();
    },


/*    resetSelectedNewLine(){
      this.selectedRowKeysArray = [];
      this.selectedRows = [];
      this.templateListDetails = [];
      this.selectedType = 1;
    },*/
    initStandardUnitList(){
      getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_details_tamplate_unit'}).then(res=>{
        if(res.success){
          this.standardUnitList = res.data;
          this.standardUnitMap = this.listToMap(this.standardUnitList,'value');
        }
      })
    },
    mqListener(){
      console.log(this.mqVisible)
      console.log(this.mqLoad)
      console.log(this.mqData)
      this.initData(this.mqData);
    },
    backToIndex(){
      let mqData = this.mqData;
      this.$emit('update:mqVisible', 1);
      this.$emit('update:mqLoad', false);
      mqData.id = 0;
      mqData.inMethod = "";
      this.$emit('update:mqData', mqData);
    },

    /**
     * 展开图标
     * @param props
     * @returns {string|*}
     */
    expandIcon(props){
        if(props.record.detailList&&props.record.detailList.length>0){

          if (props.expanded) {
            return <p-icon type='minus-square' onClick={e => {props.onExpand(props.record, e);}}/>;
          }else{
            return <p-icon type='plus-square' onClick={e => {props.onExpand(props.record, e);}}/>;
          }

        }else{
          return "";
        }
    },
    openPdSnDetailModal(){
      this.pdSnDetailModalVisible = true;
    },

    openViewBasicPhoto(){
      this.dPhVisible = true;
      let obj = JSON.parse(this.baseInfoData.photoUrl);
      this.dPhUrl = obj[0].filePath;
    },

    queryCustReport(){
      let d = this.baseInfoData;
      let data = {
        sendBillno:d.sendBillno,
        sendBillnoLine:d.sendBillnoLine,
        custno:d.custno,
        mcode:d.mcode,
      }
      postAction('/mes-quality/mesQcIncomeBasicInfo/selectBySendBilloAndLineno',data).then(res=>{
        if(res.success){
          this.custReportModalVisible = true;
        }else{
          this.$message.warning(res.msg);
        }
      })
    },

    initDefectLevelOptions(){
      getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_err_level'}).then(res=>{
        if(res.success){
          this.defectLevelOptions = res.data;
        }
      })
    },
    initInspectMethodList(){
      getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_inspect_method'}).then(res=>{
        if(res.success){
          this.inspectMethodList = res.data;
          this.inspectMethodMap = this.listToMap(this.inspectMethodList,'value');
        }
      })
    },
    initSimpleMethodList(){
      getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'rc_inspect_method'}).then(res=>{
        if(res.success){
          this.simpleMethodList = res.data;
          this.simpleMethodMap = this.listToMap(this.simpleMethodList,'value');
        }
      })
    },
    //封装listToMap
    listToMap(list,name){
      let map = {};
      for(let i in list){
        map[list[i][name]] = list[i];
      }
      return map;
    },

    /**
     * 初始化加载数据
     */
    initData(query){
      if(!query.id){
        this.$message.warning("请通过来料检任务清单选择单号进入！");

      }else{
        let id = query.id;
        let inMethod = query.inMethod;
        //设置 visible属性 -- 用于是否显示 流程审批处理操作栏
        this.visible = ""+inMethod;

        getAction('/mes-quality/mesQcIncomeBasicInfo/query/all/info/by/id/'+id).then(res=>{
          if (res.success) {
            if(res.code!=0){
              this.$message.warning(res.msg)
            }
              let data = res.data;

              data.checkBy = this.$store.state.user.name;
              data.matSnText = data.matSn==1?'SN':'PN';
              data.simpleMethodText = this.simpleMethodMap?this.simpleMethodMap[data.sampingMethod]?this.simpleMethodMap[data.sampingMethod].title:'':'';


              if(data.inMethod==1){
                let fKey = 1;
                data.checkProjectList.forEach(item=>{
                  item.key =  fKey;

                  fKey =  fKey +1;
                })
              }
              this.baseInfoData = data;
            this.individualJudgmentChange();
           /* this.initSampleTemplateList(data.sendBillno)*/
            this.templateList = data.allCheckProjectList;
          } else {
            this.$message.warning(res.msg);
          }
        })

      }
    },
    /**
     *加载检验项目列表
     */
    initSampleTemplateList(sendBillno){

      getAction('/mes-quality/mesQcIncomeBasicInfo/querySampleTemplateList/'+ sendBillno).then(res=>{

        if (res.success) {
          let data = res.data;
          this.templateList = data;
        } else {
          this.$message.warning(res.msg);
        }
      })
    },

    /**
     * 删除检验项目
     */
    deleteCheckProject(e){
      let id = e.id;
      if(id){
          deleteAction('/mes-quality/mesQcIncomeBasicInfo/deleteMesQcIncomeCheckProject/'+id).then(res=>{
            if(res.success){
              this.$message.success("删除成功");
              this.initData(this.mqData);
            }else{
              this.$message.warning(res.msg);
            }
          })
      }else{

      }


    },

    openPhUpBtn2(record){
      console.log(record)
      this.currentD = record;
      this.currentDetailPhObj = record.photoUrl;
      this.phUpVisible2 = true;

    },
    openPhReviewBtn2(record){
      this.dPhVisible = true;
      let obj = JSON.parse(record.photoUrl);
      this.dPhUrl = obj[0].filePath;
    },

    phUpSave2(){
      let data = {
        id:this.currentD.id,
        photoUrl:this.currentDetailPhObj
      }

      let r = this.currentD;
      postAction('/mes-quality/mesQcIntoWarehouseInspectTask/updateIncomeDetail',data).then(res=>{
        if(res.success){
          this.$message.success('操作成功!');
          this.phUpVisible2 = false;
          this.baseInfoData.checkProjectList[r.key-1].photoUrl = this.currentDetailPhObj;
        }else{
          this.$message.warning(res.msg)
        }
      })
    },
    /**
     * 点击‘新增行’按钮
     */
    addCheckProjectBtn(){
     this.addCPModalVisible = true;
    },

    /**
     * 确定添加
     */
    sureAddCheckProject(){

      let data = this.baseInfoData;
      let data2 = this.selectedRows[0];
      data2.basicInfoId = this.baseInfoData.id;
      putAction('/mes-quality/mesQcIncomeBasicInfo/entity/operation',data).then(res=>{
        if(res.success){
          putAction('/mes-quality/mesQcIncomeBasicInfo/addCheckProjectList',data2).then(res=>{
            if(res.success){
              this.$message.success("新增成功！");
              this.resetRadioSelect();
              this.addCPModalVisible = false;
              this.initData(this.mqData);
            }else{
              this.$message.warning(res.msg);
            }
          })
        }else{
          this.$message.warning(res.msg);
        }
      })




    },
    /**
     * 取消-关闭modal
     */
    closeAddCPModal(){
      this.resetRadioSelect();
      this.addCPModalVisible = false;
    },

    /**
     * 重设radio
     */
    resetRadioSelect(){
      this.selectedRowKeysArray = [];
      this.selectedRows = [];
      this.templateListDetails = [];
      this.selectedType = 1;
    },

    /**
     * 保存按钮
     */
    saveDataBtn(){
      let data = this.baseInfoData;
      putAction('/mes-quality/mesQcIncomeBasicInfo/entity/operation',data).then(res=>{
        if(res.success){
          this.$message.success("保存成功");
          this.initData(this.mqData);
        }else{
          this.$message.warning(res.msg);
        }
      })
    },

    /**
     * 提交按钮
     */
    submitData(){
      let data = this.baseInfoData;
      let flag = true;
      console.log(data)

      if (data.simpleQty === '') {
        //为空
        flag = false;
        this.$message.error("请输入抽检数量");
      } else {
        //不为空
        if(data.simpleQty>data.checkProjectList.length){
          flag = false;
          this.$message.error("检验项目数量不能小于抽检数量！");
        }
      }


      if(data.inMethod==2){
        if(!data.operation||data.operation===""){

          flag = false;
          this.$message.error("请选择 通过/驳回 ！");
        }
        if(data.inspectMethod===""){
          flag = false;
          this.$message.error("请选择检验方式 ！");
        }
        if(data.operation==2&&(!data.remark||data.remark=='')){
          flag = false;
          this.$message.error("驳回后必填驳回的原因 ！");
        }
      }


      if(flag){
        putAction('/mes-quality/mesQcIncomeBasicInfo/submit/entity',data).then(res=>{
          if(res.success){
            this.$message.success("操作成功");
            this.backToIndex();
          }else{
            this.$message.warning(res.msg);
          }
        })
      }



    },

    /**
     * 检验项目单选框change事件
     */
    onSelectChange(selectedRowKeys, selectedRows){
      this.selectedRowKeysArray = selectedRowKeys;
      this.selectedRows = selectedRows;
      this.templateListDetails = selectedRows[0].detailList;
      if(this.templateListDetails.length>0){
        this.selectedType=2
      }else{
        this.selectedType=3
      }


    },

    /**
     * 单项判定更改
     */
    individualJudgmentChange(){
      let basicFlag = true;
      this.baseInfoData.checkProjectList.forEach(item=>{
        let flag = true;
        let hasChild = false;
       item.detailList.forEach(item2=>{
         hasChild = true;

         if(!item2.valueType||item2.valueType==""){
           item2.individualJudgment = 2;
         }else{
           if(item2.valueType==2){
             item2.individualJudgment = item2.measuredValue=="PASS"?1:2;
           }else{

             if((item2.upperValue&&item2.upperValue!='')&&(!item2.downValue||item2.downValue=="")){
               if(item2.measuredValue<=item2.upperValue){
                 item2.individualJudgment = 1;
               }else{
                 item2.individualJudgment = 2;

               }
             }else if((item2.downValue&&item2.downValue!='')&&(!item2.upperValue||item2.upperValue=="")){
               if(item2.measuredValue>=item2.downValue){
                 item2.individualJudgment = 1;
               }else{
                 item2.individualJudgment = 2;

               }
             }else{
               if(item2.measuredValue<=item2.upperValue&&item2.measuredValue>=item2.downValue){
                 item2.individualJudgment = 1;
               }else{
                 item2.individualJudgment = 2;

               }
             }

           }
         }


        if(!item2.individualJudgment||item2.individualJudgment==2||item2.individualJudgment==""){
           basicFlag = false;
           flag = false;
         }
       })

        if(hasChild){
          if(flag){
            item.inspectResult = 1;
          }else{
            item.inspectResult = 2;
          }
        }


      })
      if(basicFlag){

        this.baseInfoData.inspectResult = 1;
      }else{

        this.baseInfoData.inspectResult = 2;
      }


    }



  },
};
</script>
<style scoped>
@import "~@assets/less/common.less";
.title {
  padding: 8px 12px;
  background: #fafafa;
}
.title:not(:first-child) {
  margin-top: 25px;
}
/deep/ .poros-form{
  margin-top:15px;
}
/deep/ .poros-table-body {
  overflow-x: auto !important;
}
/deep/ .poros-col{
  min-height: 54px;
}
.highlight {
  background-color: rgb(255, 192, 105);
  padding: 0px;
}
.myImg{
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}
</style>
